package com.timbrungardt.running.pages.run;

import com.timbrungardt.running.entities.Run;
import com.timbrungardt.running.pages.Index;

import fr.exanpe.t5.lib.constants.ExanpeEventConstants;

import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.beaneditor.Validate;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.hibernate.annotations.CommitAfter;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;


public class CreateRun {

	@Property
	private Run run;
	
	@Property
    @Persist
    private int sliderValue;
    
    @InjectComponent
    private Zone zone;

    @OnEvent(ExanpeEventConstants.SLIDER_EVENT)
    Object handleSliderAjaxEvent(String value)
    {
        return zone.getBody();
    }

	@Inject
	private Session session;

	@InjectPage
	private Index index;

	@CommitAfter
	Object onSuccess() {
		session.persist(run);

		return index;
	}
	

}
